<?php
/**
 * 后台登录控制器
 */
Class LoginAction extends Action{
   public function index(){
  	//登录页面视图
     $this->display();
   }
   //登录表单操作
   Public function login(){
   	 // p($_POST);
   	if(!IS_POST) halt('页面不存在');

   	if(I('code','','strtolower') != session('verify'))$this->error('验证码错误');

   	$db = M('user');
   	$user = $db->where(array('username' => I('username')))->find();
   	// p($user);
   	if (!$user || $user['password'] != I('password','','md5')){
   		$this->error('帐号或密码错误!');
   	}

   	$data=array(
   		'id' => $user['id'],
   		'logintime' =>time(),
   		'loginip' =>get_client_ip()
   		);
   	$db->save($data);

   	session('uid',$user['id']);
   	session('username',$user['username']);
   	session('logintime',date('Y-m-d H:i:s',$user['logintime']));
   	session('loginip',$user['loginip']);

   	// p($_SESSION);
   	redirect(__GROUP__);




   }

   Public function verify(){
   	import('Class.Image',APP_PATH);
   	Image::Verify();
   }
}
?>